package repository

import (
	"goweb2/internal/model"
	"goweb2/pkg/db"
)

// CreateUser 创建用户
func CreateUser(user *model.User) error {
	return db.DB.Create(user).Error
}

// FindUserByUsername 通过用户名查找用户
func FindUserByUsername(username string) (*model.User, error) {
	var user model.User
	result := db.DB.Where("username = ?", username).First(&user)
	if result.Error != nil {
		return nil, result.Error
	}
	return &user, nil
}

// GetAllUsers 获取所有用户
func GetAllUsers() ([]model.User, error) {
	var users []model.User
	result := db.DB.Find(&users)
	if result.Error != nil {
		return nil, result.Error
	}
	return users, nil
}
